package cz.spock.parser.service;

import org.springframework.stereotype.Service;

import cz.spock.core.service.BaseService;
import cz.spock.parser.entity.TagPattern;
import cz.spock.parser.entity.TripletPattern;

/**
 * provides business methods for working with triple patterns
 * 
 * triple patterns are prepared to be used with usage of RE, but rewrite rules are not able to provide functionality for this
 * 
 * @author miso
 *
 */
@Service
public class TripletPatternService extends BaseService {
    

    public TripletPattern setStartTag(TagPattern tag, TripletPattern pattern) {
        if(pattern == null) return null; 
        pattern.setStartTag(tag);
        return pattern;
    }
    
    public TripletPattern setContent(TagPattern tag, TripletPattern pattern) {
        if(pattern == null) return null; 
        pattern.setContent(tag);
        return pattern;
    }
    
    public TripletPattern setEndTag(TagPattern tag, TripletPattern pattern) {
        if(pattern == null) return null; 
        pattern.setEndTag(tag);
        return pattern;
    }
    
    public TripletPattern setAllowRecursion(boolean recursion, TripletPattern pattern) {
        if(pattern == null) return null; 
        pattern.setAllowRecursion(recursion);
        return pattern;
    }
    
    public TripletPattern setWeight(int weight, TripletPattern pattern) {
        if(pattern == null) return null;
        pattern.setWeight(weight);
        return pattern;
    }
    
    public TripletPattern setWeight(TripletPattern pattern) {
        if(pattern == null) return null;
        pattern.setWeight(0);
        return pattern;
    }
    
    // TODO
    public TripletPattern validateAndSave(TripletPattern pat) {
        // TODO validation
        return this.save(pat);
    }
    
    public TripletPattern save(TripletPattern pat) {
        if(pat == null) return null;
        pat.setId(dao.put(pat).getId());
        return pat;
    }
    

}
